<?php
$em = require __DIR__ . '/../example/em.php';

use Service\UserManager;

$manager = new UserManager($em);
$user = $manager->getEntity($user->getId());
$session_data = unserialize($_SESSION['auth']);
$admin_id = $session_data->getId();
?>
<!-- aditional stylesheets -->
<!-- main content -->
<div class="container">

    <?php if ($user->getBalance() > 0) : ?>
        <div class="row-fluid">
            <div class="span12">
                <div class="w-box">
                    <div class="w-box-header">
                        <h4>Пополнение номера</h4>
                    </div>
                    <div class="w-box-content  cnt_a">
                        <div class="span3">
                            <label>Введите номер</label>
                            <input id="number_balance" type="text" placeholder="37282705028" class="span8">
                        </div>
                        <div class="span3">
                            <label>Введите сумму</label>
                            <input id="amount_balance" type="text" placeholder="<?php echo $user->getBalance(); ?>"
                                   class="span8">
                        </div>
                        <br/>
                        <button id="number_balance_submit" type="submit" class="btn btn-beoro-3">Пополнить</button>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?>
</div>
<div class="footer_space"></div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#number_balance_submit").click(function (e) {
            if ($("#amount_balance").val().length < 1) {
                $.sticky('Укажите сумму пополнения!', {autoclose: 6000, position: "top-center", type: "st-error"});
                return false;
            }
            if ($("#number_balance").val().length != 11) {
                $.sticky('Не верный формат номера телефона!', {autoclose: 6000, position: "top-center", type: "st-error"});
                return false;
            }
            e.preventDefault();
            var result = <?php echo $user->getBalance(); ?> -$("#amount_balance").val();
            $.post("ajax/userProfile.php", { name: "balance", pk: <?php echo $user->getId(); ?>, value: result, sum: $("#amount_balance").val(), phone_number: $("#number_balance").val()},
                function (data) {
                    $.sticky('Номер пополнен!', {autoclose: 6000, position: "top-center", type: "st-success"});
                });
        });
    });
</script>